package fr.lip6.move.care;

import fr.lip6.move.care.CareGen;
import fr.lip6.move.care.CompileResult;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.InputOutput;
import sdmakerz_v1.coresyntax.generator.interfaces.IContext;
import sdmakerz_v1.coresyntax.generator.interfaces.IDiagramRefData;
import sdmakerz_v1.coresyntax.generator.interfaces.IInterfaceData;
import sdmakerz_v1.coresyntax.sDMakerV1.Obj;
import sdmakerz_v1.coresyntax.sDMakerV1.Type;

@SuppressWarnings("all")
public class CareObjGen {
  private CareGen mainGenerator;
  
  public CareObjGen(final CareGen mainGenerator) {
    this.mainGenerator = mainGenerator;
  }
  
  public CompileResult compile(final IContext context, final Obj obj) {
    CompileResult compileResult = CompileResult.EMPTY_RESULT;
    IDiagramRefData _diagramRefData = context.getDiagramRefData();
    String _name = obj.getName();
    String newObjName = _diagramRefData.getNewName(_name);
    IInterfaceData interfaceData = null;
    CharSequence charSequenceResult = null;
    String _name_1 = obj.getName();
    String _plus = ("for " + _name_1);
    String _plus_1 = (_plus + " newObjName=");
    String _plus_2 = (_plus_1 + newObjName);
    InputOutput.<String>println(_plus_2);
    String _name_2 = obj.getName();
    int _compareTo = newObjName.compareTo(_name_2);
    boolean _equals = (_compareTo == 0);
    if (_equals) {
      Type _type = obj.getType();
      String _identifier = _type.getIdentifier();
      IInterfaceData _interfaceDataByName = context.getInterfaceDataByName(_identifier);
      interfaceData = _interfaceDataByName;
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("Actor ");
      String _name_3 = obj.getName();
      _builder.append(_name_3, "");
      _builder.append(" = new Actor(\"");
      String _name_4 = obj.getName();
      _builder.append(_name_4, "");
      _builder.append("\", ");
      String _interfaceID = interfaceData.getInterfaceID();
      _builder.append(_interfaceID, "");
      _builder.append("); ");
      _builder.newLineIfNotEmpty();
      _builder.append("actors.add(");
      String _name_5 = obj.getName();
      _builder.append(_name_5, "");
      _builder.append(");");
      _builder.newLineIfNotEmpty();
      charSequenceResult = _builder;
      String _name_6 = obj.getName();
      CompileResult _compileResult = new CompileResult(charSequenceResult, _name_6, 
        false);
      compileResult = _compileResult;
    }
    return compileResult;
  }
}
